package com.useeinfo.framework.sugar.tools;

import org.apache.commons.lang.StringUtils;

import java.lang.reflect.Field;

public class ObjectNullUtil {

    public static boolean isAllFieldNull(Object obj) {
        Class stuClass = obj.getClass();
        Field[] fs = stuClass.getDeclaredFields();
        boolean flag = true;
        for (Field f : fs) {
            f.setAccessible(true);
            String val = "";// 得到此属性的值
            try {
                val = String.valueOf(f.get(obj));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            if (StringUtils.isNotBlank(val) && !"null".equals(val)) {//只要有1个属性不为空,那么就不是所有的属性值都为空
                flag = false;
                break;
            }
        }
        return flag;
    }
}
